
import Vue from 'vue';
import Router from 'vue-router';
Vue.use(Router);
/* Layout */
import Layout from '@/layout';
/* Router Modules */
/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */
/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
    {
        path: '/redirect',
        component: Layout,
        hidden: true,
        children: [
            {
                path: '/redirect/:path*',
                component: () => import('@/views/redirect/index')
            }
        ]
    },
    {
        path: '/login',
        component: () => import('@/views/login/index'),
        hidden: true
    },
    {
        path: '/auth-redirect',
        component: () => import('@/views/login/auth-redirect'),
        hidden: true
    },

    {
        path: '/404',
        component: () => import('@/views/error-page/404'),
        hidden: true
    },

    {
        path: '/401',
        component: () => import('@/views/error-page/401'),
        hidden: true
    },
    {
        path: '/noauth', // 无权限操作
        component: () => import('@/views/data/noAuth'),
        hidden: true
    },
	{
		path: '/workbrench',
		component: Layout,
		redirect: 'noRedirect',
		meta: { icon: 'nested', permission: 'bug' },
		children: [
			{
				path: 'index',
				component: () => import('@/views/workbench/index'),
				name: 'bug',
				meta: { title: '工作台', icon: 'user', affix: true}
			},
		]
	},
    {
        path: '/',
        component: Layout,
        redirect: '/dashboard',
		meta: { icon: 'component', permission: 'prototype' },
        children: [
            {
                path: 'dashboard',
                component: () => import('@/views/dashboard/index'),
                name: 'Dashboard',
                meta: { title: '样机登记', icon: 'dashboard', affix: true}
            }
        ]
    },
	{
		path: '/quotation',
		component: Layout,
		redirect: 'noRedirect',
		meta: { icon: 'nested', permission: 'quotation' },
		children: [
			{
				path: 'index',
				component: () => import('@/views/quotation/index'),
				name: 'quotation',
				meta: { title: '报价单管理', icon: 'nested', affix: true}
			},
			{
				path: '/quotationDetail/:id',
				name: 'detail',
				component: () => import('@/views/quotation/detailData'),
				meta: { title: '报价单详情' },
				hidden: true
			},
		]
	},
	{
		path: '/bug',
		component: Layout,
		redirect: 'noRedirect',
		meta: { icon: 'nested', permission: 'bug' },
		children: [
			{
				path: 'index',
				component: () => import('@/views/bugAdmin/index'),
				name: 'bug',
				meta: { title: '缺陷管理', icon: 'excel', affix: true}
			},
			,
			{
				path: '/bugDetail/:id',
				name: 'detail',
				component: () => import('@/views/bugAdmin/bugDetail'),
				meta: { title: '缺陷详情' },
				hidden: true
			},
		]
	},
	{
		path: '/testingReport',
		component: Layout,
		redirect: 'noRedirect',
		meta: { icon: 'edit', permission: 'report' },
		children: [
			{
				path: 'index',
				component: () => import('@/views/testingReport/index'),
				name: 'bug',
				meta: { title: '测试报告管理', icon: 'skill', affix: true}
			},
		]
	},
	{
		path: '/task',
		component: Layout,
		redirect: 'noRedirect', // noRedirect
		name:'task',
		meta: {
			title: '测试任务管理',
			icon: 'edit',
			permission: 'task_management'
		},
		children: [
			{
				path: '/orderManagement',
				component: () => import('@/views/orderManagement/index'),
				name: 'orderManagement',
				meta: { title: '订单管理', affix: true, permission: 'order' }
			},
			{
				path: '/testTask',
				component: () => import('@/views/testTask/index'),
				name: 'testTask',
				meta: { title: '测试任务管理', affix: true ,permission: 'task'}
			},
			{
				path: '/detail/:id',
				name: 'detail',
				component: () => import('@/views/orderManagement/detailData'),
				meta: { title: '订单详情' },
				hidden: true
			},
			{
				path: '/detailTask/:id',
				name: 'detailTask',
				component: () => import('@/views/testTask/detailTask'),
				meta: { title: '任务详情' },
				hidden: true
			},
			{
				path: '/testingreport/:id/:num',
				name: 'testingreport',
				component: () => import('@/views/testTask/testingreport'),
				meta: { title: '生成测试报告' },
				hidden: true
			}
		]
	},
	{
		path: '/resourceManagement',
		component: Layout,
		redirect: 'noRedirect', // noRedirect
		name:'resourceManagement',
		meta: {
			title: '资源管理',
			icon: 'table',
			permission: 'source'
		},
		children: [
			{
				path: 'role',
				component: () => import('@/views/role/index'),
				name: 'Dashboard',
				meta: { title: '用户管理', affix: true , permission: 'user'}
			},
			{
				path: 'testGroup',
				component: () => import('@/views/testGroup/index'),
				name: 'testGroup',
				meta: { title: '测试组管理', affix: true , permission: 'group' }
			},
			{
				path: 'factoryManagement',
				component: () => import('@/views/factoryManagement/index'),
				name: 'factoryManagement',
				meta: { title: '客户管理', affix: true , permission: 'manufactor' }
			},
			{
				path: 'product',
				component: () => import('@/views/product/index'),
				name: 'product',
				meta: { title: '产品', affix: true , permission: 'product' }
			},
			{
				path: 'productLine',
				component: () => import('@/views/productLine/index'),
				name: 'product',
				meta: { title: '产品线', affix: true , permission: 'product_line'}
			},
			{
				path: 'device',
				component: () => import('@/views/device/index'),
				name: 'product',
				meta: { title: '设备管理', affix: true , permission: 'test_device'}
			},
		]
	}

];
const createRouter = () =>
    new Router({
        // mode: 'history', // require service support
        scrollBehavior: () => ({ y: 0 }),
        routes: constantRoutes
    });
const router = createRouter();
export function resetRouter() {
    const newRouter = createRouter();
    router.matcher = newRouter.matcher; // reset router
	console.log(router,89898989)
}
export default router;
